package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.crowdsource.UploadProjectFileUrlFormBean;
import com.info.zhiduoduo.admin.model.formbean.project.*;
import com.info.zhiduoduo.admin.service.ProjectService;
import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.core.service.common.ContractDocService;
import com.info.zhiduoduo.core.service.common.DocService;
import com.info.zhiduoduo.repository.dto.project.MakerAllProjectDto;
import com.info.zhiduoduo.repository.dto.project.ProjectBriefDto;
import com.info.zhiduoduo.repository.dto.project.ProjectDto;
import com.info.zhiduoduo.repository.dto.project.ProjectJiugeOfflinePayDto;

import com.info.zhiduoduo.repository.entity.company.CompanyAccount;
import com.info.zhiduoduo.repository.entity.company.CompanyProject;
import com.info.zhiduoduo.repository.entity.invoice.Invoice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/project")
public class ProjectController {

	@Autowired
	ProjectService projectService;
	@Autowired
	DocService docService;
	@Autowired
	ContractDocService contractDocService;
//
//	@ApiOperation("获取项目列表")
//	@PostMapping("/list")
//	public SmartResult<ProjectBriefDto> getProjectList(@RequestBody BaseSimpleFormBean<ProjectListFormBean> formBean) {
//		return projectService.getProjectList(formBean);
//	}
//
//	@ApiOperation("获取项目详情")
//	@PostMapping("/detail")
//	public SmartResult<ProjectDto> getProjectDetail(@RequestBody BaseSimpleFormBean<Integer> formBean) {
//		return projectService.getProjectDetail(formBean);
//	}
//
//	/**
//	 * 编辑项目
//	 */
//	@ZddLog(type = ZddLogType.UPDATE,name = "编辑项目",entities = @LogEntity(entity = CompanyProject.class,parameters =
//	@LogParameter(fields = "projectid",parameters = "formBean.reqdata.projectid")))
//	@PostMapping("/edit")
//	public SmartResult editProject(@RequestBody BaseSimpleFormBean<EditProjectFormBean> formBean) {
//		return projectService.editProject(formBean);
//	}
//
//	/**
//	 * 仲裁项目金额
//	 */
//	@PostMapping("/arbitrate")
//	public SmartResult arbitrateProject(@RequestBody BaseSimpleFormBean<ArbitrateFormBean> formBean) {
//		return projectService.arbitrateProject(formBean);
//	}
//
////	/**
////	 * 下载项目合同
////	 *
////	 * @param response
////	 * @param projectid
////	 */
////	@GetMapping("/downloadContract")
////	public void downloadContract(HttpServletResponse response, @RequestParam("projectid") int projectid) {
////		docService.downloadContract(response, projectid);
////	}
//
//	@ApiOperation("下载项目合同PDF版本")
//	@GetMapping("/downloadContractPdf")
//	public void downloadContractPdf(HttpServletResponse response, @RequestParam("projectid") int projectid) {
//		contractDocService.downloadContract(response, projectid);
//	}
//
//	@ApiOperation("批量下载项目合同PDF版本")
//	@GetMapping("/batchDownloadContractPdfZip")
//	public void batchDownloadContractPdf(HttpServletResponse response, @RequestParam String projectIds) {
//		contractDocService.batchDownloadContractPdfZip(response, projectIds);
//	}
//
//	/**
//	 * 计算项目相关的合伙人的佣金和总服务费
//	 *
//	 * @param formBean
//	 * @return
//	 */
//	@PostMapping("/calcProjectPartnerBrokerage")
//	public SmartResult calcProjectPartnerBrokerage(@RequestBody BaseSimpleFormBean<Integer> formBean) {
//		return projectService.calcProjectPartnerBrokerage(formBean);
//	}
//
//	/**
//	 * 取消项目，还未验收的项目都可以取消
//	 *
//	 * @param formBean
//	 * @return
//	 */
//	@ZddLog(type = ZddLogType.UPDATE,name = "取消项目",entities = @LogEntity(entity = CompanyAccount.class,parameters =
//	@LogParameter(fields = "projectid",parameters = "formBean.reqdata")))
//	@PostMapping("/cancel")
//	public SmartResult cancelProject(@RequestBody BaseSimpleFormBean<Integer> formBean) {
//		return projectService.cancelProject(formBean);
//	}
//
//	@ZddLog(type = ZddLogType.UPDATE,name = "作废项目",entities = @LogEntity(entity = CompanyProject.class,parameters =
//	@LogParameter(fields = "projectId",parameters = "formBean.reqdata.projectId")))
//	@PostMapping("/useless")
//	public SmartResult uselessProject(@RequestBody BaseSimpleFormBean<UselessProjectFormBean> formBean) {
//		return projectService.uselessProject(formBean);
//	}
//
//	@ApiOperation(value = "下载创客项目列表", tags = "下载excel")
//	@GetMapping("/downloadProjectList")
//	public void downloadProjectList(HttpServletResponse response,
//	                                @ApiParam(name = "name", value = "模糊搜索关键字") @RequestParam(name = "name", required = false) String name,
//	                                @ApiParam(name = "startDate", value = "开始时间") @RequestParam(name = "startDate", required = false) Long start,
//	                                @ApiParam(name = "endDate", value = "结束时间") @RequestParam(name = "endDate", required = false) Long end,
//									@ApiParam(name = "projectStartDate", value = "项目完成开始时间") @RequestParam(name = "projectStartDate", required = false) Long projectStart,
//									@ApiParam(name = "projectEndDate", value = "项目完成结束时间") @RequestParam(name = "projectEndDate", required = false) Long projectEnd,
//	                                @ApiParam(name = "state", value = "1草稿 2待发布 4已发布 6竞标中 8竞标结束 10进行中 12验收中 13 验收完成 14 拒绝验收 20已完成 " +
//			                                "40已取消 44删除") @RequestParam(name = "state", required = false, defaultValue = "0") int state,
//	                                @ApiParam(name = "categoryid", value = "项目分类") @RequestParam(name = "categoryid", required = false,
//			                                defaultValue = "0") int categoryid,
//	                                @ApiParam(name = "whetherUploadFile", value = "是否上传证据链") @RequestParam(name = "whetherUploadFile",
//			                                required = false, defaultValue = "0") int whetherUploadFile,
//									@ApiParam(name = "auth",value = "授权") @RequestParam(name = "auth",required = false, defaultValue = "0") int auth
//									)
//			throws IOException {
//		Date startDate = null, endDate = null;
//		if (start != null) {
//			startDate = new Date(start);
//		}
//		if (end != null) {
//			endDate = new Date(end);
//		}
//		Date projectStartDate=null;
//		Date projectEndDate=null;
//		if (projectStart != null) {
//			projectStartDate = new Date(projectStart);
//		}
//		if (projectEnd != null) {
//			projectEndDate = new Date(projectEnd);
//		}
//
//		ProjectListFormBean reqdata = new ProjectListFormBean(startDate, endDate, name, state, categoryid, whetherUploadFile, 0,projectStartDate,projectEndDate,auth,0);
//		projectService.downloadProjectList(response, reqdata);
//	}
//
//	@ApiOperation("平台线下代付项目列表")
//	@PostMapping("/jiugeOfflinePayProjectList")
//	public SmartResult<ProjectJiugeOfflinePayDto> getJiugeOfflinePayProjectList(
//			@RequestBody BaseSimpleFormBean<JiugeOfflinePayProjectListFormBean> formBean) {
//		return projectService.getJiugeOfflinePayProjectList(formBean);
//	}
//
//	@ApiOperation("导出平台线下代付项目列表")
//	@GetMapping("/downloadJiugeOfflinePayProjectList")
//	public void downloadJiugeOfflinePayProjectList(HttpServletResponse response, @Valid JiugeOfflinePayProjectListFormBean formBean) {
//		projectService.downloadJiugeOfflinePayProjectList(response, formBean);
//	}
//
//	@ZddLog(type = ZddLogType.UPDATE,name = "平台线下代付项目支付完成")
//	@ApiOperation("平台线下代付项目支付完成")
//	@PostMapping("/jiugeOfflinePayProjectFinish")
//	public SmartResult projectJiugeOfflinePayFinish(@RequestBody BaseSimpleFormBean<ProjectJiugeOfflinePayFinishFormBean> formBean) {
//		return projectService.projectJiugeOfflinePayFinish(formBean);
//	}
//
//	@ApiOperation("查询单个交易记录结果(得仕)")
//	@PostMapping("/queryDaysPayTradeState")
//	public SmartResult queryDaysPayTradeState(@RequestBody BaseSimpleFormBean<Integer> formBean) {
//		projectService.queryTradeState(formBean.getReqdata());
//		return SmartResult.success();
//	}
//
//	@ApiOperation("导入历史成交的 项目")
//	@PostMapping("/importDealedProject")
//	public SmartResult importDealedProject(@RequestParam("file") MultipartFile file, @RequestParam("userid") int userid,
//										   @RequestParam("payId") int payId,@RequestParam("whetherJiYong") int whetherJiYong) {
//		return projectService.importDealedProject(file, userid, payId, whetherJiYong);
//	}
//
//	@ZddLog(type = ZddLogType.DELETE,name = "删除导入历史成交的 项目",entities = @LogEntity(entity = Invoice.class,parameters =
//	@LogParameter))
//	@ApiOperation("删除导入历史成交的 项目")
//	@PostMapping("/deleteImportDealedProject")
//	public SmartResult deleteImportDealedProject(@RequestBody BaseSimpleFormBean<Object[]> formBean) {
//
//		return projectService.deleteImportDealedProject(formBean);
//	}
//
//	@ZddLog(type = ZddLogType.UPDATE, name = "上传 项目证据链")
//	@ApiOperation("上传 项目证据链")
//	@PostMapping("/uploadProjectFileUrl")
//	public SmartResult uploadProjectFileUrl(@RequestBody BaseSimpleFormBean<UploadProjectFileUrlFormBean> formBean) {
//		return projectService.uploadProjectFileUrl(formBean);
//	}
//
//	@ZddLog(type = ZddLogType.CREATE, name = "批量生成 项目交付物")
//	@ApiOperation("批量生成 交付文档")
//	@PostMapping("/generateProjectDeliveryFile")
//	public SmartResult generateProjectDeliveryFile(@RequestBody BaseSimpleFormBean<GenerateProjectAcceptance> formBean){
//		return projectService.generateProjectDeliveryFile(formBean);
//	}
//
//	@ApiOperation("下载 /众包项目验收压缩文件")
//	@GetMapping("/downloadProjectDeliveryZipFile")
//	public void downloadProjectDeliveryZipFile(HttpServletResponse response,
//											   @RequestParam("compid") int compid,
//											   @RequestParam("projectType") int projectType,
//											   @RequestParam("templateType") int templateType,
//											   @RequestParam("projectIdList") List<Integer> projectIdList) {
//		projectService.downloadProjectDeliveryZipFile(response, compid, projectType, templateType, projectIdList);
//	}
//
	@ApiOperation("获取个人用户所有项目列表")
	@PostMapping("/getMakerAllProjectList")
	public SmartResult<MakerAllProjectDto> getMakerAllProjectList(@RequestBody BaseSimpleFormBean<QueryMakerAllProjectFormBean> formBean) {
		return projectService.getMakerAllProjectList(formBean);
	}

	@ApiOperation("导出个人用户所有项目列表")
	@GetMapping("/exportMakerAllProjectList")
	public void getMakerAllProjectList(HttpServletResponse response, QueryMakerAllProjectFormBean formBean) {
		projectService.exportMakerAllProjectList(response, formBean);
	}
//
//	@ApiOperation("项目退费")
//	@PostMapping("/projectRefunds")
//	public SmartResult projectRefunds(@RequestBody BaseSimpleFormBean<CompanyProject> formBean) {
//		return projectService.projectRefunds(formBean);
//	}
}
